<template>
	<div class="view">
		<Table highlight-row border stripe 
			:loading="data.isLoading" 
			:columns="columns" 
			:data="data.data">
		</Table>
	</div>
</template>

<script>
	import CWorksItemView from '@/pages/works/view/CWorksItemView';
	import {formatTimestamp} from '@/libs/date-util.js';
	
	export default {
		props: ['data'],
		components : {
			CWorksItemView
		},
		data() {
			return {
				columns : [
					{
						type: 'index',
						width: 60,
						fixed: 'left',
						align: 'center'
					},
					{
						title: '作品',
						key: 'wid',
						width: 220,
						fixed: 'left',
						align: 'center',
						render: (h, params) => {
                            return h(CWorksItemView, {
                            		props: {
                            			data: params.row
                            		}
                            });
                        }
					},
					{
						title: '提交人',
						key: 'wid',
						width: 150,
						align: 'center',
						render: (h, params) => {
							var acc = JSON.parse(params.row.accountInfo);
                            return acc.accName;
                        }
					},
					{
						title: '提交时间',
						key: 'wid',
						width: 150,
						align: 'center',
						render: (h, params) => {
                            return formatTimestamp(params.row.submitTime * 1000);
                        }
					},
					{
						title: '创建时间',
						key: 'createTime',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return formatTimestamp(params.row.createTime * 1000);
                        }
					},
					{
						title: '操作',
						key: 'state',
						width: 300,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
                            var $this = this;
							var btns = [];
							btns.push(h('Button', {
                                    props: {
                                        type: 'ghost',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            $this.editItem(params)
                                        }
                                    }
                                }, '编辑'));
                            btns.push(h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            $this.editTags(params)
                                        }
                                    }
                                }, '编辑详情'));
                            btns.push(h('Button', {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            $this.publishItem(params)
                                        }
                                    }
                                }, '发布作品'));
                            btns.push(h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            $this.rejectItem(params)
                                        }
                                    }
                                }, '驳回作品'));
                            return h('div', btns);
                        }
					}
				]
			}
		},
		methods: {
			editItem(params) {
				this.$emit('on-click', 'edit', params)
			},
			editTags(params) {
				this.$emit('on-click', 'edit-tags', params)
			},
			publishItem(params) {
				this.$emit('on-click', 'publish', params)
			},
			rejectItem(params) {
				this.$emit('on-click', 'reject', params)
			}
		}
	}
</script>

<style scoped="scoped">
	
</style>